Skip to content

Fix sign loss when scanning negative sexagesimal scalars#806

Open
chatman-media wants to merge 1 commit into
ruby:masterfrom
chatman-media:fix-negative-sexagesimal-scalar
Open

Fix sign loss when scanning negative sexagesimal scalars#806
chatman-media wants to merge 1 commit into
ruby:masterfrom
chatman-media:fix-negative-sexagesimal-scalar

Conversation

@chatman-media

Copy link
Copy Markdown

Ran into this while parsing some YAML with negative time offsets. ScalarScanner#tokenize splits sexagesimal values like 190:20:30 on : and parses each segment with to_i/to_f, but the minus sign only sticks to the first segment since that's the only one String#to_i actually sees it on. So -190:20:30 comes out as -682770 instead of -685230 — the 20 and 30 parts silently stay positive and get added instead of subtracted.

Same bug in both the int and float branches. Fix strips the sign once up front and applies it to the final sum, which matches how PyYAML (and the yaml.org spec) handle this. Added a couple of regression tests for negative sexagesimal int/float.

ScalarScanner#tokenize only applied the leading minus/plus to the
first colon-separated segment (via String#to_i/#to_f), so a value
like "-190:20:30" came out as -682770 instead of -685230 because the
20 and 30 parts kept their positive sign. Strip the sign once up
front and apply it to the final sum instead, matching the yaml.org
sexagesimal spec (and what PyYAML does). Added regression tests for
the negative int and float cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant